package com.sunwayworld.basemodule.common.eptstorage.acqconfig.service.impl;

import com.sunwayworld.basemodule.common.eptstorage.acqconfig.bean.LimsEquiptAcqConfigInstBean;
import com.sunwayworld.basemodule.common.eptstorage.acqconfig.dao.LimsEquiptAcqConfigInstDao;
import com.sunwayworld.basemodule.common.eptstorage.acqconfig.net.NetEptSenderHelper;
import com.sunwayworld.basemodule.common.eptstorage.acqconfig.service.LimsEquiptAcqConfigInstService;
import com.sunwayworld.basemodule.common.eptstorage.acqconfig.service.LimsEquiptAcqConfigService;
import com.sunwayworld.basemodule.rm.equipment.bean.LimsEquipmentBean;
import com.sunwayworld.framework.at.annotation.AuditTrailEntry;
import com.sunwayworld.framework.at.annotation.AuditTrailType;
import com.sunwayworld.framework.context.ApplicationContextHelper;
import com.sunwayworld.framework.restful.data.RestJsonWrapperBean;
import com.sunwayworld.framework.spring.annotation.GikamBean;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
@GikamBean
public class LimsEquiptAcqConfigInstServiceImpl implements LimsEquiptAcqConfigInstService {

    private static final Logger logger = LogManager.getLogger(LimsEquiptAcqConfigInstServiceImpl.class);

    @Autowired
    private LimsEquiptAcqConfigInstDao limsEquiptAcqConfigInstDao;

    @Autowired
    @Lazy
    private LimsEquiptAcqConfigService limsEquiptAcqConfigService;

    @Autowired
    private NetEptSenderHelper netEptSenderHelper;

    @Override
    @SuppressWarnings("unchecked")
    public LimsEquiptAcqConfigInstDao getDao() {
        return limsEquiptAcqConfigInstDao;
    }

    @Override
    @Transactional
    @AuditTrailEntry(AuditTrailType.INSERT)
    public Long insert(RestJsonWrapperBean jsonWrapper) {
        LimsEquiptAcqConfigInstBean limsEquiptAcqConfigInst = jsonWrapper.parseUnique(LimsEquiptAcqConfigInstBean.class);
        limsEquiptAcqConfigInst.setId(ApplicationContextHelper.getNextIdentity());
        getDao().insert(limsEquiptAcqConfigInst);
        return limsEquiptAcqConfigInst.getId();
    }

    @Override
    @Transactional
    public String requestEquiptTempAndHum(LimsEquipmentBean equiptBean) {
        String temperture = netEptSenderHelper.synSend(equiptBean,"tempatureData");
        String humidity = netEptSenderHelper.synSend(equiptBean,"humidityData");
        return temperture+","+humidity;
    }
}
